package com.myq.note.service.impl;

import com.myq.note.dao.BookDao;
import com.myq.note.po.Book;
import com.myq.note.po.Result;
import com.myq.note.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class BookServiceImpl implements BookService {

    @Autowired
    public BookDao bookDao;

    @Override
    public Result findById(String user_id) {
        List<Book> list = bookDao.findById(user_id);
        //System.out.println(list);
        Result<List<Book>> result = new Result<>();
        result.setData(list);
        result.setMes("成功");
        result.setStatus(200);


        return result;
    }

    @Override
    public Result createBook(Book book) {

        String uuid = UUID.randomUUID().toString();
        book.setBook_id(uuid);
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        book.setBook_createtime(format);
        book.setBook_lastmodify(format);
        bookDao.createBook(book);
        Result<Book> result = new Result<>();
        result.setData(book);
        result.setStatus(200);


        return result;
    }
}
